<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>管理员页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
                <a href="">管理员首页</a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="电话 " name="tele" id="tele"></div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="username" placeholder="用户名" autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>

                <div class="layui-card-body ">
                    <table class="layui-table"
                           lay-data="{url:'./adminList',page:true,toolbar: '#toolbarDemo',id:'test'}" lay-filter="test">
                        <thead>
                        <tr>
                            <th lay-data="{type:'checkbox'}">ID</th>
                            <th lay-data="{field:'username', width:100, sort: true}">用户名</th>
                            <th lay-data="{field:'tele', minWidth:200, sort: true}">手机号</th>
                            <th lay-data="{field:'role',  Width: 100  ,templet:function(data){
                                            if(data.role == 1)
                                                return '超级管理员';
                                            if(data.role == 2)
                                                return '普通管理员';
                                        }}">角色
                            </th>
                            <th lay-data="{templet: '#newsListBar',minWidth:300}">操作</th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<!--操作-->
<script type="text/html" id="newsListBar">
    <!--不允许删除自己，只能删除比自己级别低的人-->
    {{# if ( USER.role < d.role && USER.id!=d.id) { }}
    <a class="layui-btn layui-btn-xs" id="edit" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" id="updatepassword" lay-event="updatepassword">一键改密</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" id="del" lay-event="del">删除</a>
    {{# } }}
    <a class="layui-btn layui-btn-xs " id="look" lay-event="look">详情</a>
</script>
<script type="text/html" id="toolbarDemo">
    {{# if ( USER.role==1 ) { }}
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="addAdmin">
            <i class="layui-icon">&#xe654;</i>
            添加用户
        </button>
        <!--<button class="layui-btn layui-btn-sm" lay-event="delBatch"> 批量删除</button>-->
    </div>
    {{# } }}
</script>
<script>
    var USER = JSON.parse(window.sessionStorage.getItem("user"));
</script>
<script>layui.use(['table', 'form', 'layer'],
    function () {
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var layer = layui.layer;
        //监听表单的提交事件
        form.on('submit(sreach)', function (data) {
            table.reload("test", {
                page: {
                    curr: 1
                    //重新从第 1 页开始
                },
                where: data.field
            });
            return false;
        });

        table.on('toolbar(test)',
            function (obj) {
                switch (obj.event) {
                    case 'addAdmin':
                        xadmin.open('添加', './adminAdd.html', 600, 400);
                        break;
                }
            });

        table.on('tool(test)', function (obj) {
            switch (obj.event) {
                case 'edit':
                    xadmin.open("修改信息", './adminUpdateData.html?' + obj.data.id, 600, 400);
                    break;
                case 'updatepassword':
                    xadmin.open("一键改密码", './adminUpdateAdminPass.html?' + obj.data.id, 600, 400);
                    break;
                case 'look':
                    xadmin.open("详情页",'./adminInfo.html?' + obj.data.id, 600, 400);
                    break;
                case "del":
                    var data = obj.data;
                    layer.confirm('确定删除吗？', function (index) {
                        delAdmin(data, index, obj);
                    });
                    break;
            }
        });
        function delAdmin(data, index, obj) {
            var id = obj.data.id;
            $.get("delAdmin", {id: id}, function (data) {
                alert(data.msg);
                xadmin.father_reload();
            });
        }

    });
</script>

</html>